<?php
/**
 * 定单管理模型
 * @author e5
 *
 */
class OrderModel extends Model{
	public $table = "order";
	public $validate = array(
			array("arid","nonull","收货地址不能为空",2,3),
			array("sendtype","nonull","配送方式不能为空",2,3),
			array("paytype","nonull","支付方式不能为空",2,3)
	);
	public $map = array(
			'arid'=>'vshop_address_arid'
	);
	/**
	 * 添加定单
	 * @return boolean
	 */
	public function addOrder() {
		if (!$this->create()) return false;
		$this->data['onumber'] = Cart::getOrderId();
		$this->data['ototal'] = Cart::getTotalPrice();
		$this->data['otime'] = time();
		$this->data['vshop_user_uid'] = session("uid");
		$oid = $this->add();
		if (!$oid){
			$this->error = "定单提交失败";
			return false;
		}
		//添加定单列表
		K("OrderList")->addOrderList($oid);
		return true;
	}
}